home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.sources.wanted,comp.lang.c,comp.unix.programmer
- Subject: Re: Seek unix2dos.c OR help with tr
- Date: 15 Mar 96 19:10:54 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.826917054@rscernix>
- References: <4i0946$7io@nuke.csu.net> <danpop.826545577@rscernix> <4i9dj4INN7kl@keats.ugrad.cs.ubc.ca> <4ia0kj$d8s@solutions.solon.com> <31488F4F.726E@oc.com>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <31488F4F.726E@oc.com> Larry Weiss <lfw@oc.com> writes:
-
- >Peter Seebach wrote:
- > >
- > > In article <4i9dj4INN7kl@keats.ugrad.cs.ubc.ca>,
- > > Kazimir Kylheku <c2a192@ugrad.cs.ubc.ca> wrote:
- > > >When I know that I'm specifically dealing with ASCII control chars, I have a
- > > >macro like:
- > > >#define CTRL(C) ((C)-64)
- > > >which I then use with capital letters:
- > > > switch(char) {
- > > > case CTRL('M'):
- >
- > >
- > > I always use
- > > #define CTRL(x) ((x) & 0x1f)
- > > because this preserves the likely semantics of CTRL.
- >
- >Peter, Is this just a matter of self-evident documentation of the
- > macro definition?
-
- It definitely is, for someone who knows how the CTRL key works.
-
- >Dan Pop, how would have coded Kazimir's example to avoid the
- >reference to the magic-number 64 -and- how would you have coded
- >Peter's alternative that uses magic-number 0x1f ?
-
- Magic numbers are OK in macro definitions. How else do you expect to
- hide magic numbers behind macros???
-
- Moreover, 0x1f is not a magic number _in this context_ any more than 2
- is a magic number in a binary search algorithm or 3.1415926 is a magic
- number when computing the circumference of a circle. All of them are
- natural constants. They're self-documenting and aren't expected to be
- changed later, by the code maintainer.
-
- As for Kazimir's example, a "better" definition would be:
-
- #define CTRL(C) ((C) - 'A' + 1)
-
- Satisfied?
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-